//package com.amumu.drama.portal.service.impl;
//
//import com.amumu.drama.portal.domain.MemberBrandAttention;
//import com.amumu.drama.portal.repository.MemberBrandAttentionRepository;
//import com.amumu.drama.portal.service.MemberAttentionService;
//import com.amumu.drama.common.moudles.member.service.UmsMemberService;
//import com.amumu.drama.mapper.PmsBrandMapper;
//import com.amumu.drama.model.PmsBrand;
//import com.amumu.drama.model.UmsMember;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.domain.Pageable;
//import org.springframework.stereotype.Service;
//
//import java.util.Date;
//
///**
// * 会员关注Service实现类
// * Created by macro on 2018/8/2.
// */
//@Service
//public class MemberAttentionServiceImpl implements MemberAttentionService {
//    @Value("${mongo.insert.sqlEnable}")
//    private Boolean sqlEnable;
//    @Autowired
//    private PmsBrandMapper brandMapper;
//    @Autowired(required = false)
//    private MemberBrandAttentionRepository memberBrandAttentionRepository;
//    @Autowired
//    private UmsMemberService memberService;
//
//    @Override
//    public int add(MemberBrandAttention memberBrandAttention) {
//        int count = 0;
//        if(memberBrandAttention.getBrandId()==null){
//            return 0;
//        }
//        UmsMember member = memberService.getCurrentMember();
//        memberBrandAttention.setMemberId(member.getId());
//        memberBrandAttention.setMemberNickname(member.getNickname());
//        memberBrandAttention.setMemberIcon(member.getIcon());
//        memberBrandAttention.setCreateTime(new Date());
//        MemberBrandAttention findAttention = memberBrandAttentionRepository.findByMemberIdAndBrandId(memberBrandAttention.getMemberId(), memberBrandAttention.getBrandId());
//        if (findAttention == null) {
//            if(sqlEnable){
//                PmsBrand brand = brandMapper.selectByPrimaryKey(memberBrandAttention.getBrandId());
//                if(brand==null){
//                    return 0;
//                }else{
//                    memberBrandAttention.setBrandCity(null);
//                    memberBrandAttention.setBrandName(brand.getName());
//                    memberBrandAttention.setBrandLogo(brand.getLogo());
//                }
//            }
//            memberBrandAttentionRepository.save(memberBrandAttention);
//            count = 1;
//        }
//        return count;
//    }
//
//    @Override
//    public int delete(Long brandId) {
//        UmsMember member = memberService.getCurrentMember();
//        return memberBrandAttentionRepository.deleteByMemberIdAndBrandId(member.getId(),brandId);
//    }
//
//    @Override
//    public Page<MemberBrandAttention> list(Integer pageNum, Integer pageSize) {
//        UmsMember member = memberService.getCurrentMember();
//        Pageable pageable = PageRequest.of(pageNum-1,pageSize);
//        return memberBrandAttentionRepository.findByMemberId(member.getId(),pageable);
//    }
//
//    @Override
//    public MemberBrandAttention detail(Long brandId) {
//        UmsMember member = memberService.getCurrentMember();
//        return memberBrandAttentionRepository.findByMemberIdAndBrandId(member.getId(), brandId);
//    }
//
//    @Override
//    public void clear() {
//        UmsMember member = memberService.getCurrentMember();
//        memberBrandAttentionRepository.deleteAllByMemberId(member.getId());
//    }
//}
